﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace
#if WINDOWS_PHONE
    PServiceBus.WindowsPhone
#else
 PServiceBus.Silverlight
#endif
{
    public class ScriptConstants {
        public const string InitDurableFlag = "var subdurable = {0}";
        public const string SetDurableFlag = "subdurable = {0};";
        public const string BeforeUnload = @"
window.onbeforeunload = function(){{
    if(!subdurable) {{
        invokeUrl(""{0}GetDeleteSubscriber?ReThrowException={1}&ESBUserName={2}&ESBPassword={3}&name={4}"");
    }}
    invokeUrl(""{0}GetDisconnect?ReThrowException={1}&ESBUserName={2}&ESBPassword={3}&name={4}"");
}};
";
        public const string InvokeUrl = @"
function invokeUrl(url) {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject(""Msxml2.XMLHTTP"");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject(""Microsoft.XMLHTTP"");
			} catch (e) {
				return false;
			}
		}
	}
	try {
		xmlHttp.open(""GET"", url, false);
		xmlHttp.send();
	} catch (e) {
	}
}";
    }
}
